package algorithm;

/**
 * 给定一个整数数组 nums 和一个目标值 target，请你在该数组中找出和为目标值的那 两个 整数，并返回他们的数组下标。
 * @author rongkai
 * @description:
 * @date 2021/3/7
 */
public class Solution8 {

    public static void main(String[] args) {
        int[] nums = {1,3,5,7,9};
        int target = 12;
        int[] solution = solution(nums, target);
        for (int i : solution) {
            System.out.println(i);
        }
    }

    /**
     * 简单粗暴，双指针遍历
     * @param nums
     * @param target
     * @return
     */
    public static int[] solution(int[] nums,int target){
        int[] index = new int[2];
        boolean check = false;
        index[1] = 1;
        for (int i = 0; i < nums.length; i++) {
            index[0] = i;
            for (int j = i+1; j < nums.length; j++) {
                if (nums[i] + nums[j] == target){
                    index[1] = j;
                    check = true;
                    break;
                }
            }
            if (check){
                break;
            }

        }
        return index;
    }
}
